import os
import time
SYSTEM = 'windows'


class Lock(object):
    @staticmethod
    def get_file_lock():
        return FileLock()


class FileLock(object):
    def __init__(self):
        lock_file = 'FLASK_LOCK'
        lock_dir = os.environ['tmp']

        self.file = '%s%s%s' % (lock_dir, os.sep, lock_file)
        self._fn = None
        self.release()

    def acquire(self):
        while os.path.exists(self.file):
            time.sleep(0.01)  # wait 10ms
            continue
        with open(self.file, 'w') as f:
            f.write('1')

    def release(self):
        if os.path.exists(self.file):
            os.remove(self.file)
